﻿using System;
using System.Configuration;

using NUnit.Framework;

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace mvcForum.Tests.WebUI {

	[TestFixture]
	public class D050_BasicForumTest {
		private static IWebDriver driver;

		#region Initialization and cleanup
		[TestFixtureSetUp]
		public static void TestInitialize() {
			driver = TestHelper.GetDriver();
		}

		[TestFixtureTearDown]
		public static void TestCleanup() {
			if (driver != null) {
				driver.Close();
			}
		}
		#endregion

		[Test]
		public void TestBasicForumForum1() {
			driver.VisitURL("forum");
			//driver.Navigate().GoToUrl(String.Format("{0}forum", TestHelper.SiteBaseURL));

			var link = driver.FindElement(By.LinkText("Forum 1"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			Assert.AreEqual(String.Format("{0}forum/viewforum/forum-1/1", TestConfiguration.SiteBaseURL), driver.Url.ToLower());

			link = driver.FindElement(By.LinkText("Post a new topic"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			Assert.AreEqual(String.Format("{0}forum/account/logon?returnurl=%2fforum%2ftopic%2fcreate%2f1", TestConfiguration.SiteBaseURL), driver.Url.ToLower());
		}

		[Test]
		public void TestBasicForumForum2() {
			driver.VisitURL("forum");
			//driver.Navigate().GoToUrl(String.Format("{0}forum", TestHelper.SiteBaseURL));

			var link = driver.FindElement(By.LinkText("Forum 2"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			Assert.AreEqual(String.Format("{0}forum/viewforum/forum-2/2", TestConfiguration.SiteBaseURL), driver.Url.ToLower());

			link = driver.FindElement(By.LinkText("Post a new topic"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			Assert.AreEqual(String.Format("{0}forum/account/logon?returnurl=%2fforum%2ftopic%2fcreate%2f2", TestConfiguration.SiteBaseURL), driver.Url.ToLower());
		}

		[Test]
		public void TestBasicForumForum3() {
			driver.VisitURL("forum");
			//driver.Navigate().GoToUrl(String.Format("{0}forum", TestHelper.SiteBaseURL));

			var link = driver.FindElement(By.LinkText("Forum 3"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			Assert.AreEqual(String.Format("{0}forum/viewforum/forum-3/3", TestConfiguration.SiteBaseURL), driver.Url.ToLower());

			link = driver.FindElement(By.LinkText("Post a new topic"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			Assert.AreEqual(String.Format("{0}forum/account/logon?returnurl=%2fforum%2ftopic%2fcreate%2f3", TestConfiguration.SiteBaseURL), driver.Url.ToLower());
		}

		[Test]
		public void TestBasicForumCategory1() {
			driver.VisitURL("forum");
			//driver.Navigate().GoToUrl(String.Format("{0}forum", TestHelper.SiteBaseURL));

			var link = driver.FindElement(By.LinkText("CATEGORY 1"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(2);

			Assert.AreEqual(String.Format("{0}forum/viewcategory/category-1/1", TestConfiguration.SiteBaseURL), driver.Url.ToLower());

			link = driver.FindElement(By.LinkText("Forum 1"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			link = driver.FindElement(By.LinkText("Post a new topic"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			Assert.AreEqual(String.Format("{0}forum/account/logon?returnurl=%2fforum%2ftopic%2fcreate%2f1", TestConfiguration.SiteBaseURL), driver.Url.ToLower());
		}

		[Test]
		public void TestBasicForumCategory2() {
			driver.VisitURL("forum");
			//driver.Navigate().GoToUrl(String.Format("{0}forum", TestHelper.SiteBaseURL));

			var link = driver.FindElement(By.LinkText("CATEGORY 2"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			Assert.AreEqual(String.Format("{0}forum/viewcategory/category-2/2", TestConfiguration.SiteBaseURL), driver.Url.ToLower());

			link = driver.FindElement(By.LinkText("Forum 3"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			link = driver.FindElement(By.LinkText("Post a new topic"));
			Assert.IsNotNull(link);
			link.Click();
			driver.Wait(1);

			Assert.AreEqual(String.Format("{0}forum/account/logon?returnurl=%2fforum%2ftopic%2fcreate%2f3", TestConfiguration.SiteBaseURL), driver.Url.ToLower());
		}
	}
}